﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DungeonAdventure.Library.Objects.Misc
{
    public class ConfigItem
    {
        #region Properties

        public string Name { get; set; }
        public object Value { get; set; }
        public Type Type { get; set; }

        #endregion

        #region Ctor

        #endregion

        #region Functions

        public static ConfigItem Create(String name, Object value, Type type)
        {
            return new ConfigItem{Name = name, Value = value, Type = type};
        }        

        public string GetValue()
        {
            return Value.ToString();
        }

        public bool GetValue(bool defaultValue)
        {
            bool b;
            return bool.TryParse(GetValue(), out b) ? b : defaultValue;
        }

        public int GetValue(int defaultValue)
        {
            int i;
            return int.TryParse(GetValue(), out i) ? i : defaultValue;
        }

        public double GetValue(double defaultValue)
        {
            double d;
            return double.TryParse(GetValue(), out d) ? d : defaultValue;
        }

        public long GetValue(long defaultValue)
        {
            long l;
            return long.TryParse(GetValue(), out l) ? l : defaultValue;
        }

        #endregion
    }
}
